
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class CoinBuyTip : BasePanel
{
    //金币
    public string coinNum;
    public Text coinText;
    //脚本
    public ItemModify objSc;
    //两个按钮
    public Button okButton;
    public Button closeButton;

    public override void OnClose()
    {
        base.OnClose();

        GameManager.Instance.canOprate=true;
    }

    public override void OnInit()
    {
        base.OnInit();

        path="UI/OtherTip/CoinBuyTip";

        GameManager.Instance.canOprate=false;
    }

    public override void OnShow(params object[] par)
    {
        base.OnShow(par);

        coinText=item.transform.Find("Bg/Text").GetComponent<Text>();
        closeButton=item.transform.Find("Close").GetComponent<Button>();
        okButton=item.transform.Find("Ok").GetComponent<Button>();

        coinNum=(string)par[0];
        objSc=(ItemModify)par[1];

        coinText.text="是否花费<color=yellow> "+coinNum+" 金币 </color>购买 <color=yellow> "+objSc.myName+" </color>";

        closeButton.onClick.AddListener(CloseButton);
        okButton.onClick.AddListener(OkButton);
    }

    //关闭
    public void CloseButton()
    {
        Close();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"],1f);
    }
    //OK
    public void OkButton()
    {
        //查看金币是否足够
        if (GameManager.Instance.coin>=int.Parse(coinNum))
        {
            GameManager.Instance.coin-=int.Parse(coinNum);
            //添加效果
            objSc.RunOut();
            //移除此
            objSc.transform.parent.GetComponent<RandomRoomManager>().CloseItem(objSc.gameObject);

            TipSayManager.Instance.Say("购买<color=yellow> 成功 </color>");
        }
        else
        {
            TipSayManager.Instance.Say("金币<color=yellow> 不足 </color>");
        }

        CloseButton();
    }
}
